import org.junit.jupiter.api.Test;

/**
 * @Description
 * @ClassName test
 * @Author 山山大魔王
 * @Date 2021/12/10 11:42
 * @Version 1.0
 */
public class test {
    public boolean fanduan(int[][] mar,int midx,int midy,int target){
        if (mar[midy][midx]==target)
            return true;
        if (mar.length>midy&&mar[midy+1][midx]==target)
            return true;
        if (mar[0].length>midx&&mar[midy][midx+1]==target)
            return true;
        if (mar.length>midy&&mar[0].length>midx&&mar[midy+1][midx+1]==target)
            return true;
        return false;
    }
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        int lox=0,loy=0;
        int hix=matrix[0].length,hiy=matrix.length;

        while(lox<hix&&loy<hiy){
            int midx = lox+(hix-lox)/2;;
            int midy = loy + (hiy - loy)/2;;


            if(matrix[midy][midx]>target){
                hix = midx;
                hiy = midy;
            }else if(matrix[midy][midx]<target){
                lox = midx;
                loy = midy;
            }else {
                return true;
            }

        }

        return false;
    }

    @Test
    public void text(){
        int[][] matrix= {{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
        findNumberIn2DArray(matrix,20);
    }
}
